"use client"; import React, {useState} from 'react' import { ServiceTypes } from "@/api/customservice"; import { Link } from "@/i18n"; import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore"; import { useSocialStore } from "@/stores/useSocials"; import { Badge } from "antd-mobile"; import { useTranslations } from "next-intl"; import { FC, useEffect } from "react"; import PopupHby from "@/app/[locale]/(TabBar)/(entire)/promo/PopupHby"; import { redPacketApi,lredPacketApi } from "@/api/promo"; import { getToken } from "@/utils/Cookies"; import { getUserMoneyApi } from "@/api/user"; import { useRequest } from "ahooks"; interface Props { services: ServiceTypes[]; socials: ServiceTypes[]; } const ServiceWidget: FC = (props) => { const token = getToken(); const [isShowRedPacket, setIsShowRedPacket] = useState(false); const [isShowRedIcon,setIsShowRedIcon] = useState(false) const { services, socials } = props; const defaultService = services.find((item) => item.is_suspend === 1); const newServices = services.filter((item) => item.is_suspend !== 1); const setSocials = useSocialStore((state) => state.setSocials); useEffect(() => { // 数据存储,侧边栏使用 setSocials(socials); }, []); const t = useTranslations("HomePage"); const { unread } = useGlobalNoticeStore((state) => ({ unread: state.unread, })); const getRedPacketInfo =async()=>{ try{ let redPacketInfo:any let actList:any = [] if(token){ redPacketInfo =await lredPacketApi() actList = redPacketInfo.data?.red_packets || [] }else{ redPacketInfo =await redPacketApi() actList = redPacketInfo.data || [] } // 是否有已开始但是没领过的红包 let isHasStartAct = actList.filter((aItem:any)=>{ return !!aItem.is_start && !aItem.is_receive }) let isShowRed = isHasStartAct.length>0 setIsShowRedIcon(isShowRed) }catch(error){ console.log('redPacketInfo===>error:',error) } } // 红包雨轮询 useRequest(getRedPacketInfo, { pollingInterval: 180000, pollingErrorRetryCount: 1, pollingWhenHidden: false, onSuccess: (data) => { console.log('data',data) }, }); return ( <> {/* 红包雨icon */} { isShowRedIcon && (
{setIsShowRedPacket(true)}} />
) } {/* 红包弹窗 */} { isShowRedPacket && ({setIsShowRedPacket(false)}} />) } {defaultService && ( )}
= 5 ? 5 : newServices.length}`}> {newServices.map((service, index) => { return ( ); })}
{t("Service")}
{/*share*/}
{t("Share")}
= 5 ? 5 : socials.length}`}> {socials.map((service, index) => { return ( ); })}
); }; export default ServiceWidget;